<?php

namespace app\index\controller;

use think\Controller;
use think\Db;


class Node extends IndexController
{
    public function index()
    {
        $list = DB::table('qq_node')
            ->paginate(5);

//        $page = $list->render();

        return view('index/node', [
            'title' => '节点列表',
            'list' => $list

        ]);
    }

    public function edit($id)
    {
        $list = DB::table('qq_node')
            ->where('id=' . $id)
            ->find();

        return view('index/node_edit', [
            'title' => '编辑用户信息',
            'list' => $list
        ]);
    }

    public function doedit()
    {
//        echo '111';
        $file = request()->post();
        $id = $file['id'];
        unset($file['id']);

//        dump($file);
        $data = DB::table('qq_node')
            ->where('id', $id)
            ->update($file);

        if ($data) {
            $this->success('修改成功');
        } else {
            $this->error('修改失败');
        }
    }


    public function delete($id)
    {
        $data = Db::table('qq_node')->where('id',$id)->delete();

        if($data){
            return true;
        }
    }


    public function create()
    {
        return view('index/node_add');
    }

    public function save()
    {
        $list = request()->post();

        $data = DB::table('qq_node')
            ->insert($list);
        if ($data) {
            return $this->success('提交成功', url('index/node/index'));
        } else {
            $this->error('提交失败');
        }
    }
}